<script lang="ts" setup>
import { reactive, onMounted } from 'vue'

// do not use same name with ref
const formData = reactive({
    form: {
    kg: '开启',
    sh: '开启',
    pl: '1',
    dz: '1',
    }
})

const onSubmit = () => {
    console.log('submit!')
}

import axios from 'axios'
import { ElMessage } from 'element-plus';
const getDtpz = () => {
    //参考接口文档，请求用户数据
    axios.get("/api/u/dongTaiPeiZhi/").then((response) => {
        console.log(response, "网站信息数据reponse")
        //更新用户数据
        formData.form = response.data[0]
        console.log(formData.form, "接收网站信息数据")
    })
}

onMounted(() => {
    getDtpz()
})

const updateDtpz = () => {
    console.log(formData.form, "<-----1111修改网站信息数据")
    axios.patch("/api/u/dongTaiPeiZhi/1/",
        formData.form,
        { headers: { "Content-Type": "application/json" } }   //
    ).then((response) => {
        console.log(response, "<-----修改网站信息数据")
        // 更新用户数据
        formData.form = response.data
        ElMessage({
            type: "success",
            message: "信息保存成功"
        })
    })

}

</script>


<template>
    <el-form :model="formData.form" label-width="auto" style="max-width: 700px">
        <el-form-item label="动态认证开关">
            <el-select v-model="formData.form.kg">
                <el-option label="开启" value="开启" />
                <el-option label="关闭" value="关闭" />
            </el-select>
        </el-form-item>
        <el-form-item label="动态审核">
            <el-select v-model="formData.form.sh">
                <el-option label="开启" value="开启" />
                <el-option label="关闭" value="关闭" />
            </el-select>
        </el-form-item>
        <el-form-item label="评论权重值">
            <el-input v-model="formData.form.pl" />
        </el-form-item>
        <el-form-item label="点赞权重值">
            <el-input v-model="formData.form.dz" />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="updateDtpz">保存</el-button>
        </el-form-item>
    </el-form>
</template>

<style scoped>
.el-form-item h3 {
    color: #999;
    font-size: 14px;
}

.el-button {
    margin-left: 108px;
}
</style>
